import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

const store = new Vuex.Store({
	modules: {

	},
  state: {
		loading: false,
    cacheEnabled: true // 是否启用缓存
  },
  mutations: {
		showLoading(state) {
			state.loading = true
		},
		hideLoading(state) {
			state.loading = false
		},
    setCacheEnabled(state, enabled) {
      state.cacheEnabled = enabled;
    }
  },
  actions: {
    clearCache({ commit }) {
      commit('setCacheEnabled', false); // 禁用缓存
      // 延迟恢复缓存，避免立即重新缓存
      setTimeout(() => {
        commit('setCacheEnabled', true);
      }, 0);
    }
  }
});

export default store;
